home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10625 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: variable-lenght argument list
  5. Date: 18 Mar 1996 18:36:16 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4ikvi0$89n@solutions.solon.com>
  8. References: <4icl0o$b3j@saturn.exodus.net> <GDR11.96Mar18184655@cl.cam.ac.uk>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <GDR11.96Mar18184655@cl.cam.ac.uk>,
  12. Gareth Rees <gdr11@cl.cam.ac.uk> wrote:
  13. >I note that the GNU coding standards suggest the following dreadful
  14. >hack, which would render your program unportable to many systems (and
  15. >maybe even to your own system should you change compiler).  But these
  16. >may not be important considerations.
  17.  
  18. >  In certain cases, it is ok to pass integer and pointer arguments
  19. >  indiscriminately to the same function, and use no prototype on any
  20. >  system.  For example, many GNU programs have error-reporting functions
  21. >  that pass their arguments along to `printf' and friends:
  22.  
  23. >     error (s, a1, a2, a3)
  24. >          char *s;
  25. >          int a1, a2, a3;
  26. >     {
  27. >       fprintf (stderr, "error: ");
  28. >       fprintf (stderr, s, a1, a2, a3);
  29. >     }
  30.  
  31. >  In practice, this works on all machines, and it is much simpler than
  32. >  any "correct" alternative.  Be sure *not* to use a prototype for such
  33. >  functions.
  34.  
  35. A few notes:
  36.  
  37. 1.  This fails for arguments over 3 times sizeof(int), for the obvious reason.
  38. 2.  This fails with floating point values on some machines.
  39. 3.  This uses the obsolescent feature of old-style declarations.
  40.  
  41. In practice, on any machine this works on, there is a trivial way to
  42. do things "correctly" based on <varargs.h> or <stdarg.h>.  Currently,
  43. every machine to which gcc is ported has one or the other (assuming
  44. bc-init.c compiles), and <stdarg.h> is available for all ANSI systems.
  45.  
  46. This is probably the single most glaring idiocy in the GNU coding
  47. standards.
  48.  
  49. -s
  50. -- 
  51. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  52. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  53. FUCK the communications decency act.  Goddamned government.  [literally.]
  54. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  55.